// Decompiled by GOOSIN CO,LTD Copyright 2010 Pavel Kouznetsov.
// home page: http://www.Goosin.net
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   Masking.java

package com.xml.export;

import java.io.File;
import java.util.*;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;

// Referenced classes of package com.xml.export:
//			Path

public class Masking extends Path
{

	String file;
	private SAXBuilder builder;
	private Document doc;
	private Element root;
	private static Masking mask = null;

	public Masking()
	{
		file = "";
		builder = null;
		doc = null;
		root = null;
	}

	public Masking(String filename)
	{
		file = "";
		builder = null;
		doc = null;
		root = null;
		init(filename);
	}

	public void setFile(String filename)
	{
		init(filename);
	}

	public void init(String filename)
	{
		try
		{
			file = (new StringBuilder(String.valueOf(getPath()))).append(filename).toString();
			SAXBuilder builder = new SAXBuilder();
			doc = builder.build(new File(file));
			if (doc.hasRootElement())
				root = doc.getRootElement();
		}
		catch (Exception jex)
		{
			jex.printStackTrace();
		}
	}

	public static Masking getMask()
	{
		return mask;
	}

	public List getTables()
	{
		List list = root.getChild("tables").getChildren("table");
		return list;
	}

	public String getTableNick(Element table)
	{
		return table.getAttributeValue("nick");
	}

	public String getTableName(Element table)
	{
		return table.getAttributeValue("name");
	}

	public List getColumnFields(Element table)
	{
		List columnslist = table.getChild("columns").getChildren("column");
		return columnslist;
	}

	public int getColumnCount(Element table)
	{
		return getColumnFields(table).size();
	}

	public String getColumnNick(Element column)
	{
		return column.getAttributeValue("nick");
	}

	public String getColumnName(Element column)
	{
		return column.getAttributeValue("name");
	}

	public Vector getTablesNicks()
	{
		Vector result = new Vector();
		for (Iterator i = getTables().iterator(); i.hasNext(); result.add(getTableNick((Element)i.next())));
		return result;
	}

	public Vector getTableNames()
	{
		Vector result = new Vector();
		for (Iterator i = getTables().iterator(); i.hasNext(); result.add(getTableName((Element)i.next())));
		return result;
	}

	public Hashtable getTableNamesAndNicks()
	{
		Hashtable result = new Hashtable();
		for (Iterator i = getTables().iterator(); i.hasNext(); result.put(getTableName((Element)i.next()), getTableNick((Element)i.next())));
		return result;
	}

	public Element locateTable(String tablename)
	{
		List list = getTables();
		for (Iterator tables = list.iterator(); tables.hasNext();)
		{
			Element table = (Element)tables.next();
			if (getTableName(table).equals(tablename))
				return table;
		}

		return null;
	}

	public Hashtable getColumnFieldsAndNicks(String tablename)
	{
		if (locateTable(tablename) != null)
		{
			Hashtable result = new Hashtable();
			Element col;
			for (Iterator i = getColumnFields(locateTable(tablename)).iterator(); i.hasNext(); result.put(getColumnName(col), getColumnNick(col)))
				col = (Element)i.next();

			return result;
		} else
		{
			return null;
		}
	}

	public Vector getColumnNicks(String tablename)
	{
		if (locateTable(tablename) != null)
		{
			Vector result = new Vector();
			Element col;
			for (Iterator i = getColumnFields(locateTable(tablename)).iterator(); i.hasNext(); result.addElement(getColumnNick(col)))
				col = (Element)i.next();

			return result;
		} else
		{
			return null;
		}
	}

	public Vector getColumnNames(String tablename)
	{
		if (locateTable(tablename) != null)
		{
			Vector result = new Vector();
			Element col;
			for (Iterator i = getColumnFields(locateTable(tablename)).iterator(); i.hasNext(); result.addElement(getColumnName(col)))
				col = (Element)i.next();

			return result;
		} else
		{
			return null;
		}
	}

	public String getTableNamefromNick(String tablenick)
	{
		return getTableName(locateTable(tablenick));
	}

	public String getTableNickfromName(String tablename)
	{
		return getTableNick(locateTable(tablename));
	}

}
